using System;
using System.Security.Principal;
using Votations.NSurvey.Data;
using System.Collections;

namespace Votations.NSurvey.Web.Security
{
	/// <summary>
	/// NDNNPrincipal to access and manage the web admin 
	/// section of nsurvey using a DNN user.
	/// </summary>
	public class NSurveyDNNPrincipal : INSurveyPrincipal
	{

		public INSurveyIdentity Identity { get { return _identity; } }

		public NSurveyDNNPrincipal(INSurveyIdentity identity, int[] rights)
		{
			_identity = identity;
			if (rights != null && rights.Length > 0)
			{
				// Store the rights in a local hash table
				// for easy and quick look up
				foreach (int right in rights)
				{
					NSurveyRights rightEnum = (NSurveyRights) Enum.Parse(typeof(NSurveyRights), right.ToString());
					_rights.Add(rightEnum, rightEnum);
				}
			}
		}

		public bool HasRight(NSurveyRights right)
		{
			return _rights.ContainsKey(right);
		}

		public bool IsInRole(string role)
		{
			return true;
		}

		INSurveyIdentity _identity;
		Hashtable _rights = new Hashtable();
	}
}
